<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <title>商品录入</title>
    <style>
		html{
			overflow-y:scroll;
			overflow:-moz-scrollbars-vertical;
		}
		.hotkinds{float:left;width:99%;margin-top:2px;margin-left:1%;height:auto;overflow:hidden;}
		.dl_hotkinds{margin:0 5px;padding:5px 0 0;height:28px;background:#FCFAF4;}
		.dl_hotkinds_1{margin:0 5px;padding:5px 0 0;height:28px;background:#ececec;}
		.dl_hotkinds_2{margin:0 5px;padding:5px 0 0;height:28px;}
		.dt_hotkinds{float:left;width:90px;height:22px;line-height:22px;text-align:left;margin-right:2px;display:inline;font-size:0.9pm;font-weight:bold;overflow:hidden;white-space:nowrap;}
		.dl_hotkinds dd{line-height:22px;}
		.list_nowrap{float:left;overflow:hidden;white-space:nowrap;}
		.div_header{background:#FFFFFF;border:1px solid #fff;}
	</style>
</head>

<body>

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_content">

        <div style="clear:both;"></div>
        <div class="select-box">
            <div onclick="goods.change(1);" id="select_1" class="selected">
                商品基本信息
            </div>
            <div onclick="goods.change(2);" id="select_2">
                商品规格
            </div>
            <div onclick="goods.change(3);" id="select_3">
                图片和描述
            </div>
            <div onclick="goods.change(4);" id="select_4">
                商品关键字
            </div>
            <!--div onclick="goods.change(5);" id="select_5">
                商品标签
            </div-->
        </div>

        <form name="goodsAdd_from" id="goodsAdd_from" >
        <!--商品基本信息-->
        <div class="items clearfix" id="goods_base_info" style="width:100%;">
            <h2 style="" class="tal">商品基本信息</h2>
            <div class="items2">
                <div>
                    <table style="width:90%;">
                        <tr style="height:40px;">
                            <td class="tar" width="80">商品名称：</td>
                            <td width="780">
                                <input type="text" id="goodsName" name="goodsName" maxlength="100" style="ime-mode:active;width:500px;" autocomplete="off" disabled>
                                <font color="red">*</font>
                            </td>
                        </tr>
                        <tr style="height:40px;">
                            <td class="tar">商品品牌：</td>
                            <td>
                                <select name="brandID" id="brandID" style="width:125px;" disabled>
                                    <option value="0">请选择</option>
                                    <!--{foreach from=$goods_info->goodsBrand item=brand}-->
                                    <option value="<!--{$brand->brandID}-->"><!--{$brand->brandName}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </td>
                        </tr>
                        <tr style="height:40px;">
                            <td class="tar">商品单位：</td>
                            <td>
                                <select name="unitID" id="unitID" style="width:125px;" disabled>
                                    <option value="0">请选择</option>
                                    <!--{foreach from=$goods_info->goods_unit item=unit}-->
                                    <option value="<!--{$unit->unitID}-->"><!--{$unit->unitName}--></option>
                                    <!--{/foreach}-->
                                </select>
                            </td>
                        </tr>
                        <tr style="height:40px;">
                            <td class="tar">商品简述：</td>
                            <td>
                                <textarea id="brief" name="brief" style="width:500px;height:100px; font-size:12px;" style="ime-mode:active;" autocomplete="off" disabled></textarea>
                            </td>
                        </tr>
                        <tr style="height:100px;">
                            <td class="tar">商品备注：</td>
                            <td>
                                <textarea id="memo" name="memo" style="width:500px;height:60px; font-size:12px;" style="ime-mode:active;" autocomplete="off" disabled></textarea>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        <!--商品规格-->
        <div class="items clearfix" id="goods_spec_info" style="display:none;width:100%;">
            <h2 class="tal">规格信息</h2>
            <div class="items2">
                <table style="width:100%;margin-left:14px;">
                    <tr style="height:40px;">
                        <td style="text-align:right;width:8%;">商品分类：</td>
                        <td class="tar" style="text-align:left;width:94%;padding-left:10px;">
                            <select name="bigCategoryID" id="bigCategoryID" onchange="goods.getCategorySpec(1);" style="width:125px;" disabled>
                                <option value="0">请选择</option>
                                <!--{foreach from=$goods_info->bigArray item=big}-->
                                <option value="<!--{$big->bigCategoryID}-->"><!--{$big->description}--></option>
                                <!--{/foreach}-->
                            </select>

                            <select name="midCategoryID" id="midCategoryID" onchange="goods.getCategorySpec(2);" style="width:125px;" disabled>
                                <option value="0">请选择</option>
                            </select>

                            <select name="smallCategoryID" id="smallCategoryID" onchange="goods.getCategorySpec(3);" style="width:128px;" disabled>
                                <option value="0">请选择</option>
                            </select>
                            <!--<input class="btn" type="button" name="submit" value="获取规格组信息" onclick="goods.submitSpec()">-->
                            <font color="Red">*</font>
                        </td>
                    </tr>
                    <tr style="height:40px;margin-top:24px;" class="spec colorLevel">
                        <td class="tar" style="text-align:right;">一级规格组：</td>
                        <td style="padding-left:10px;" >
                            <select class="cspecGroupID" id="cspecGroupID" name="cspecGroupID" onchange="goods.changeSpec(1)" style="width:130px">
                                <option value="0">请选择</option>
                            </select>
                        </td>
                    </tr>
                    <tr style="height:40px;" class="spec colorSpecTr">
                        <td class="tar" style="text-align:right; display:hidden" id="gg">规格：</td>
                        <td style="padding-left:10px;">
                            <div id="cspecInfo">
                                <font style="color:red;font-weight:bold;"></font>
                            </div>
                        </td>
                    </tr>
                    <tr style="height:40px;margin-top:24px;"  class="spec sizeLevel">
                        <td class="tar" style="text-align:right;">二级规格组：</td>
                        <td style="padding-left:10px;">
                            <select class="specGroupID" id="specGroupID" name="specGroupID" onchange="goods.changeSpec(2)" style="width:130px">
                                <option value="0">请选择</option>
                            </select>
                        </td>
                    </tr>
                    <tr style="height:40px;" class="spec sizeSpecTr">
                        <td class="tar" style="text-align:right; display:hidden" id="gg2">规格：</td>
                        <td>
                            <div id="specInfo" style="padding-left:10px;">
                                <font style="color:red;font-weight:bold;"></font>
                            </div>
                        </td>
                    </tr>
                    <tr style="height:40px;" class="spec">
                        <td class="tar" style="text-align:right;">销售价：</td>
                        <td style="padding-left:10px;">
                            <input type="text" id="fixedSalePrice" name="fixedSalePrice" maxlength="8" value="0" style="width:110px;">
                        </td>
                    </tr>
                    <tr style="height:40px;" class="spec">
                        <td class="tar" style="text-align:right;">市场价：</td>
                        <td style="padding-left:10px;">
                            <input type="text" id="fixedMarketPrice" name="fixedMarketPrice" maxlength="8" value="0" style="width:110px;">
                        </td>
                    </tr>
                    <tr style="height:40px;" class="spec">
                        <td class="tar" style="text-align:right;">积分价格：</td>
                        <td style="padding-left:10px;">
                            <input type="text" id="fixedAddPrice" name="fixedAddPrice" value="0" maxlength="8" value="0" style="width:110px;">
                        </td>
                    </tr>
                </table>
                <!--<div id="categoryError" style="margin:15px 0px 0px 32px;color:red;font-weight:bold;"></div>-->
            </div>
            <div id="flexContent" style="margin-bottom: 30px;">
                <form id="selector_form" onsubmit="return false;">
                    <div style="width:76%;">
                        <table id="flex"></table>
                    </div>
                </form>
            </div>
        </div>

        <!--商品图片和详情-->
        <div id="goods_picture_info" style="display:none;">
            <div class="items clearfix" style="width:100%;">
                <h2 style="" class="tal">展示图片</h2>
                <div class="items2">
                    <div>
                        <table>
                            <tr>
                                <td style="width:20%;">
                                    <div style="width:100%;">
                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
                                            <image src="" id="img_1" style="width:100%;height:100%;" ></image>
                                        </div>
                                        <div style="padding-top:5px;text-align: center;">

                                            <input type="hidden"  name="hidImg_1" id="hidImg_1" value="" >
                                        </div>
                                    </div>
                                </td>
                                <td style="width:20%;padding-left: 20px;">
                                    <div style="width:100%;">
                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
                                            <image src="" id="img_2" style="width:100%;height:100%;" ></image>
                                        </div>
                                        <div style="padding-top:5px;text-align: center;">

                                            <input type="hidden"  name="hidImg_2" id="hidImg_2" value="" >
                                        </div>
                                    </div>
                                </td>
                                <td style="width:20%;padding-left: 20px;">
                                    <div style="width:100%;">
                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
                                            <image src="" id="img_3" style="width:100%;height:100%;" ></image>
                                        </div>
                                        <div style="padding-top:5px;text-align: center;">

                                            <input type="hidden" name="hidImg_3" id="hidImg_3" value="" >
                                        </div>
                                    </div>
                                </td>
                                <td style="width:20%;padding-left: 20px;">
                                    <div style="width:100%;">
                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
                                            <image src="" id="img_4" style="width:100%;height:100%;" ></image>
                                        </div>
                                        <div style="padding-top:5px;text-align: center;">

                                            <input type="hidden" name="hidImg_4" id="hidImg_4" value="" >
                                        </div>
                                    </div>
                                </td>
                                <td style="width:20%;padding-left: 20px;">
                                    <div style="width:100%;">
                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
                                            <image src="" id="img_5" style="width:100%;height:100%;" ></image>
                                        </div>
                                        <div style="padding-top:5px;text-align: center;">

                                            <input type="hidden" name="hidImg_5" id="hidImg_5" value="" >
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
            <div class="items clearfix" style="width:100%;">
                <h2 style="" class="tal">详情描述</h2>
                <div class="items2">
                    <div>
                        <textarea name="description" id="description" style="width:100%;height:400px;visibility:hidden;"></textarea>
                    </div>
                </div>
            </div>
        </div>

        <!--商品关键字-->
        <div class="items clearfix" id="goods_keywords_info" style="display:none;width:100%;">
            <h2 style="" class="tal">关键字</h2>
            <div class="items2">
                <div>
                    <table class="dl_hotkinds" id="js_hotkinds" style="width:100%;background:#FFFFFF">
                        <tr>
                            <td id="keywordList"></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        <!--商品标签-->
        <div class="items clearfix" style="display:none;">
            <h2 style="" class="tal">商品标签</h2>
            <div class="items2">

                <input type="hidden" id="goodsID" name="goodsID" value="<!--{$goodsInfo->goodsID}-->">
                <!--{assign var="tag_group_id" value=0}-->
                <!--{assign var="group_count" value=0}-->
                <!--{assign var="cnt" value = 1}-->
                <!--{foreach from=$goods_info->tagArray item =tag_line}-->
                <!--{if $tag_group_id == 0 }-->
                <dl id="js_hotkinds" class="dl_hotkinds">
                    <dt class="dt_hotkinds" style="width:105px;text-align:center;" title="<!--{$tag_line->tagGroupName}--> - <!--{$tag_line->memoName}-->">
                        <!--{$tag_line->memoName}-->
                    </dt>
                    <dd>
                        <!--{assign var="tag_group_id" value=$tag_line->tagGroupID}-->
                        <!--{/if}-->

                        <!--{if $tag_group_id!= 0 && $tag_group_id != $tag_line->tagGroupID}-->
                        <!--{assign var="tag_group_id" value=$tag_line->tagGroupID}-->
                        <!--{assign var="group_count" value=0}-->
                        <!--{assign var="cnt" value = $cnt+1}-->
                    </dd>
                </dl>
                <dl id="js_hotkinds" <!--{if $cnt%2 == 0}--> class="dl_hotkinds_1"<!--{else}--> class="dl_hotkinds"<!--{/if}-->>
                <dt class="dt_hotkinds" style="width:105px;text-align:center;" title="<!--{$tag_line->tagGroupName}--> - <!--{$tag_line->memoName}-->">
                    <!--{$tag_line->memoName}-->
                </dt>
                <dd>
                    <!--{/if}-->
                    <!--{if $group_count!=0 && $group_count%8 == 0}-->
                </dd>
                </dl>
                <dl id="js_hotkinds" <!--{if $cnt%2 == 0}--> class="dl_hotkinds_1" <!--{else}--> class="dl_hotkinds" <!--{/if}-->>
                <dt class="dt_hotkinds" style="width:105px;text-align:center;">&nbsp;</dt>
                <dd>
                    <!--{assign var="group_count" value=0}-->
                    <!--{/if}-->
                    <!--{assign var="group_count" value=$group_count+1}-->
                    <div class="list_nowrap" style="width:105px;" title="<!--{$tag_line->tagName}-->">
                        <input type="checkbox" id="chk_<!--{$tag_line->tagID}-->" name="tag" value="<!--{$tag_line->tagGroupID}-->_<!--{$tag_line->tagID}-->" <!--{if $tag_line->checkFlg==1}-->checked<!--{/if}-->>
                        <!--{$tag_line->tagName}-->
                    </div>
                    <!--{/foreach}-->
                </dd>
                </dl>
            </div>

        </div>

        </form>
        </div>

</div>

</body>
</html>
<script>
window.editor = KindEditor.create("#description");
	//表格对象
	var table_obj = {'page' : '', 'total' : '', 'rows' : []};
	
	var COLORARRAY = '';
	var SIZEARRAY  = '';

    var tagAdd = 1; //加入的文本框计数
	
	$("#flex").flexigrid({
        url:"",
        dataType: "json",
        colModel : [
            {display: "规格 <font color='red'>*</font>", width : 140, align: "center"},
            {display: "销售价 <font color='red'>*</font>", width : 110, align: "center"},
            {display: "市场价 <font color='red'>*</font>", width : 110, align: "center"},
            {display: "积分价格 <font color='red'>*</font>", width : 110, align: "center"},
            {display: "商品条码", width : 200, align: "center"},
            {display: "商品编码", width : 200, align: "center"},
        ],
        useRp: false,
        showTableToggleBtn: true,
    });

    //隐藏规格信息
    $('.spec').hide();
    $('#flexContent').hide();
    
	var goods = {
		//切换显示标签
		change: function(flg){
			if(flg == 1){	//商品基本信息
				$('#select_1').addClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').removeClass('selected');
				
				$('#goods_base_info').css('display', 'block');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'none');
				$('#goods_tag_info').css('display', 'none');
				
			}else if(flg == 2){	//商品规格
				
				$('#select_1').removeClass('selected');
				$('#select_2').addClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').removeClass('selected');
				
				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'block');
				$('#goods_tag_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'none');
				
			}else if(flg == 3){ //图片和描述
				$('#select_1').removeClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').addClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').removeClass('selected');
				
				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'block');
				$('#goods_keywords_info').css('display', 'none');
				$('#goods_tag_info').css('display', 'none');
			}else if(flg == 4){ //商品关键字
				$('#select_1').removeClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').addClass('selected');
				$('#select_5').removeClass('selected');
				
				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'block');
				$('#goods_tag_info').css('display', 'none');
			}else if(flg == 5){ //商品标签
				$('#select_1').removeClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').addClass('selected');
				
				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'none');
				$('#goods_tag_info').css('display', 'block');
			}
		},
		
		//根据当前分类查找下级分类
		getCategory : function(flg){
        	if(flg == 1){	//大分类
        		var bigID = $('#bigCategoryID').val();
        		if(bigID == 0){
        			$('#midCategoryID').html('<option value="0">请选择</option>');
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        		}else{
        			$('#midCategoryID').html('<option value="0">请选择</option>');
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        			
        			//ajax查询中分类信息
        			var bigObj = {'flg' : 1, 'id' : bigID};
	        		$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : bigObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + '>' + v + '</option>'
								})
								
								$('#midCategoryID').html(htmlStr);
							}else if(result == 1){
								$('#midCategoryID').html('<option value="0">请选择</option>');
        						$('#smallCategoryID').html('<option value="0">请选择</option>');
							}
						}
	        		});
        		}
        	}else if(flg == 2){	//中分类
        		var bigID = $('#bigCategoryID').val();
        		var midID = $('#midCategoryID').val();
        		if(midID == 0)
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        		else{
        			//ajax查询小分类信息
        			var midObj = {'flg' : 2, 'id' : bigID + '_' + midID};
        			$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : midObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + '>' + v + '</option>'
								})
								
								$('#smallCategoryID').html(htmlStr);
							}else if(result == 1)
								$('#smallCategoryID').html('<option value="0">请选择</option>');
						}
	        		});
        		}
        	}
        },
        
        getCategorySpec : function(flg){
        	
        	$('#flex tr').remove();
        	
        	if(flg == 1){	//大分类
        		var bigID = $('#bigCategoryID').val();
        		if(bigID == 0){
        			$('#midCategoryID').html('<option value="0">请选择</option>');
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        		}else{
        			$('#midCategoryID').html('<option value="0">请选择</option>');
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        			
        			//ajax查询中分类信息
        			var bigObj = {'flg' : 1, 'id' : bigID};
	        		$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : bigObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + '>' + v + '</option>'
								})
								
								$('#midCategoryID').html(htmlStr);
							}else if(result == 1){
								$('#midCategoryID').html('<option value="0">请选择</option>');
        						$('#smallCategoryID').html('<option value="0">请选择</option>');
							}
						}
	        		});
        		}
        	}else if(flg == 2){	//中分类
        		var bigID = $('#bigCategoryID').val();
        		var midID = $('#midCategoryID').val();
        		if(midID == 0)
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        		else{
        			//ajax查询小分类信息
        			var midObj = {'flg' : 2, 'id' : bigID + '_' + midID};
        			$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : midObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + '>' + v + '</option>'
								})
								
								$('#smallCategoryID').html(htmlStr);
							}else if(result == 1)
								$('#smallCategoryID').html('<option value="0">请选择</option>');
						}
	        		});
        		}
        	}
        	
        	//绑定分类执行加载规格组
        	goods.submitSpec();
        },
        //上传图片
        uploadPic:function( flg ){
            E.open("/quanliadmin/app/uploads/goodsImage.php?flg=" + flg, "上传", {height: 200,width: 800, top: 50, left: 150});
        },

        //删除商品图片
        deletePic:function( flg ){
            $('#img_' + flg).attr('src', '');
            $('#hidImg_' + flg).val('');
        },

        //显示图片
        showImage:function( imageUrl , flg ){
            $('#img_' + flg).attr('src', '/quanliadmin/docroot/images/goods/' + imageUrl);
            $('#hidImg_' + flg).val(imageUrl);
        },
        
        //获取用户所选的分类ID返回规格组ID
        submitSpec:function(){
        	var bigCategoryID   = $.trim($("#bigCategoryID").val());
        	var midCategoryID   = $.trim($("#midCategoryID").val());
        	var smallCategoryID = $.trim($("#smallCategoryID").val());

        	if(bigCategoryID == '' || bigCategoryID == 0){
        		$('.spec').hide();
        		$('#flexContent').hide();
        		goods.specInit();
        		return false;
        	}
        	
        	var specArr = {'bigCategory' : bigCategoryID,'midCategoryID' : midCategoryID, 'smallCategoryID' : smallCategoryID};

       		$.ajax({
       			type:"POST",
       			url:"/invokingAjax-backend/goods/goodsAdd.ajax?operFlg=4",
        		dataType:"JSON",
        		data: specArr,
        		success:function(result_obj){

        			//不存在
        			if(result_obj.code == 400){
        				$('.spec').hide();
        				$('#flexContent').hide();
        				goods.specInit();
        				return;
        			}
        			
        			//存在
        			$('#categoryError').html('');
        			var htmlStrFlg = 0;
        			var htmlStr2Flg = 0;
        			var htmlStr = '<option value="0">请选择</option>';
        			var htmlStr2 ='<option value=0>请选择</option>';
					
       				for(var i=0;i<result_obj.length;i++){
       					
       					if(result_obj[i]['isColor'] == 0){ //非颜色
   							htmlStr2 += '<option value='+result_obj[i]['id']+'>'+result_obj[i]['name']+'</option>';
							htmlStr2Flg = 1;
       					}else{ //颜色
   							htmlStr += '<option value='+result_obj[i]['id']+'>'+result_obj[i]['name']+'</option>';
   							htmlStrFlg = 1;
       					}	
       				}
       				
       				$('#cspecGroupID').html(htmlStr);
       				$('#specGroupID').html(htmlStr2);
       				
       				$('.spec').show();
       				$('#flexContent').show();
       				
       				if(htmlStrFlg == 0)
       					$('.colorLevel').hide();
       					
       				if(htmlStr2Flg == 0)
       					$('.sizeLevel').hide();	
       					
       				$('.colorSpecTr').hide();
	       			$('.sizeSpecTr').hide();
        		}
        	});	
        },
        
        //规格信息初始化
        specInit : function(){
        	$('#cspecGroupID').val('0');
        	$('#specGroupID').val('0');
        	$('#cspecInfo').html('');
        	$('#specInfo').html('');
        },
        
        //生成商品信息
        addGoods : function(){
        	//规格组是否存在规格
        	var isColorSpec = $.trim($('#cspecGroupID').val());
        	var isCspecInfo = $.trim($('#cspecInfo').html());
        	var isSizeSpec = $.trim($('#specGroupID').val());
        	var isSpecInfo  = $.trim($('#specInfo').html());
        	if(parseInt(isColorSpec) != 0 && isCspecInfo == ''){
        		E.alert('一级规格组对应的标签不存在');
        		return false;
        	}
        	
        	if(parseInt(isSizeSpec) != 0 && isSpecInfo == ''){
        		E.alert('二级规格组对应的标签不存在');
        		return false;
        	}
        	
        	//一口价
        	var fixedSalePrice   = parseInt($.trim($('#fixedSalePrice').val()));
        	var fixedMarketPrice = parseInt($.trim($('#fixedMarketPrice').val()));
        	var fixedAddPrice    = parseInt($.trim($('#fixedAddPrice').val()));
        	if(!E.isMoney(fixedSalePrice) || !E.isMoney(fixedMarketPrice)){
        		E.alert('请输入正确的销售价或市场价');
        		return false;
        	}
        	
        	if(!E.isDigital(fixedAddPrice)){
        		E.alert('请输入正确的积分价格');
        		return false;
        	}
        	
        	//规格组1
			var colorArr = [];
			
			//规格组2
			var sizeArr = [];

			//已选择规格组1下的规格
			var colorInfo = $("input[type=checkbox][class=colorCls]:checked");
			
			//已选择规格组2下的规格
			var sizesInfo = $("input[type=checkbox][class=poundCls]:checked");
			
			//如果不选择规格组1则默认规格
			if(colorInfo.length == 0){
				colorArr['1000'] = '默认';
			}

			//如果不选择规格组2则默认规格
			if(sizesInfo.length == 0)
				sizeArr['1001'] = '默认';

			//选中颜色
			colorInfo.each(function(){
				colorArr[$(this).val()] = $(this).attr('title');
			})
			
			//选择尺码
			sizesInfo.each(function(){
				sizeArr[$(this).val()] = $(this).attr('title');
			})

			//根据颜色，尺码生成商品信息
			var flg = 1;
			
			//生成数据之前初始化数据
			table_obj.rows = [];
			
			for(c_key in colorArr){
				for(s_key in sizeArr){
					//商品规格
					var goodsSpec = '';
					if(flg == 1)
						goodsSpec = "<input type='radio' name='checkPrice' checked value="+flg+"> ";
					else
						goodsSpec = "<input type='radio' name='checkPrice' value="+flg+"> ";
						
					goodsSpec += colorArr[c_key] + '-' + sizeArr[s_key];
					goodsSpec += "<input type='hidden' name=colorSpec_"+flg+" value="+c_key+">";
					goodsSpec += "<input type='hidden' name=sizeSpec_"+flg+" value="+s_key+">";
					goodsSpec += "<input type='hidden' name=colorSpecName_"+flg+" value="+colorArr[c_key]+">";
					goodsSpec += "<input type='hidden' name=sizeSpecName_"+flg+" value="+sizeArr[s_key]+">";
					
					//销售价
					var salePrice = '<input type="text" id="salePrice_'+flg+'" name=salePrice_'+flg+' value='+fixedSalePrice+' style="width:80%;font-weight:bold;font-size:15px;color:red;ime-mode:disabled;" maxlength="20">';
					
					var marketPrice = '<input type="text" name=marketPrice_'+flg+' value='+fixedMarketPrice+' style="width:80%;font-weight:bold;font-size:15px;ime-mode:disabled;" maxlength="20">';
					
					var addPoints = '<input type="text" name=addPoints_'+flg+' value='+fixedAddPrice+' style="width:80%;ime-mode:disabled;" maxlength="10">&nbsp;' ;
					
					var barcode = '<input type="text" name=barcode_'+flg+' style="width:80%;ime-mode:disabled;" maxlength="60">&nbsp;' ;

                    var goodsCodes = '<div id="externalNo_div_'+flg+'_'+tagAdd+'" style="height:30px;vertical-align:middle;">'+
									 '<input style="width:150px;font-weight:bold;font-size:15px;color:red;ime-mode:disabled;margin-right:10px;" type="text" name="externalNo_'+flg+'_'+tagAdd+'" id="externalNo_'+flg+'_'+tagAdd+'">' +
									 '<img id="img_add_'+flg+'" src="/quanliadmin/docroot/images/bag_open.gif" onclick="goods.addOne('+flg+','+tagAdd+')"></div>';

					//传入表格数组
					var value = [goodsSpec , salePrice, marketPrice , addPoints, barcode, goodsCodes];
					
					table_obj.rows.push({'id' : flg, 'cell' : value});
					
					flg++ ;
					
					tagAdd ++ ;
				}
			}
			
			$("#flex").flexAddData(table_obj);	
			COLORARRAY = colorArr;
			SIZEARRAY = sizeArr;
        },
        
        //根据规格组号获取规格信息
        changeSpec : function(specFlg){
        	
        	//flg=1 规格组1  flg=2 规格组2
        	
        	$('#flex tr').remove();
        	
        	if(specFlg == 1)
        		var specGroupID = $('#cspecGroupID').val();
        	else if(specFlg == 2)
        		var specGroupID = $('#specGroupID').val();
        	
			if(specGroupID == '' || specGroupID == 0){
				if(specFlg == 1){
					$('.colorSpecTr').hide();
					$('#cspecInfo').html('');
				}else if(specFlg == 2){
					$('.sizeSpecTr').hide();
					$('#specInfo').html('');
				}	
				return false;

			}else{
				
				//ajax获取规格信息
				$.ajax({
					type: "POST",
					url: "/invokingAjax-backend/goods/goodsAdd.ajax?operFlg=2&groupID="+specGroupID,
					dataType: "JSON",
					success: function( result_obj ) {
						if(result_obj.code == 200){
							if(result_obj.message != null && result_obj.message != ''){
								var htmlStr = '';
								var flg = 1;
								$.each(result_obj.message, function(k, v){
									
									if(flg == 8)
										htmlStr += '<br/>';
										
									htmlStr += '<span style="display:inline-block;padding:8px;">';
									
									if(specFlg == 1)
										htmlStr += '<input type="checkbox" name="colors[]" class="colorCls" value='+k+' title='+v+'> ';
									else if(specFlg == 2)
										htmlStr += '<input type="checkbox" name="specSizes[]" class="poundCls" value='+k+' title='+v+'> ';
										
									htmlStr += v;
									htmlStr += '</span>';
									
									flg++;
								})
								
								if(specFlg == 1){
									$('.colorSpecTr').show();
									$()
									$('#cspecInfo').html(htmlStr);
								}else if(specFlg == 2){
									$('.sizeSpecTr').show();
									$('#specInfo').html(htmlStr);
								}	
							}else{
								if(specFlg == 1){
									$('.colorSpecTr').hide();
									$('#cspecInfo').html('');
								}else if(specFlg == 2){
									$('.sizeSpecTr').hide();
									$('#specInfo').html('');
								}	
							}	
								
						}else{
							if(specFlg == 1){
								$('.colorSpecTr').hide();
								$('#cspecInfo').html('');
							}else if(specFlg == 2){
								$('.sizeSpecTr').hide();
								$('#specInfo').html('');
							}	
						}	
					}
				})
			}	
        },
        
        //检查保存的数据
        check: function() {
            this.dt = E.getFormValues('goodsAdd_from');
            var error_msg = '';
            
            if (this.dt.goodsName == '')
                error_msg += "商品名称不能为空<br />";
            
         	if(this.dt.bigCategoryID == 0)
         		error_msg += "请选择大分类分类信息<br />";
         		
         	else if(this.dt.midCategoryID == 0)
         		error_msg += "请选择中分类分类信息<br />";
         		
         	//规格基本检查
         	var tr_length = $('#flex tr').length;
         	if(tr_length < 1)
         		error_msg += "请添加商品规格信息<br />";
         		
         	if (error_msg != ''){
                E.alert(error_msg);	
                return false;
         	}    	
         		
         	//规格详细检查	
         	var sflg = 0;	//销售价标志
			var mflg = 0;   //市场价标志
			var aflg = 0;   //积分价标志
			
			//规格信息(销售价)	
			$("input[name*=salePrice_]").each(function(){
				var p_price = $.trim($(this).val());	//销售价
				if(p_price != ''){
					//销售价
					if(!E.isNum(p_price) || p_price <= 0){
						error_msg += '销售价必须为大于0的数字<br>';
						return false;
					}
				}else{
					if(sflg == 0){
						error_msg += '请输入销售价<br/>';
						sflg = 1;
					}
				}	
			})
			
			//规格信息(市场价)	
			$("input[name*=marketPrice_]").each(function(){
				var m_price = $.trim($(this).val());	//市场价
				if(m_price != ''){
					//市场价
					if(!E.isNum(m_price) || m_price <= 0){
						error_msg += '市场价必须为大于0的数字<br>';
						return false;
					}
				}else{
					if(mflg == 0){
						error_msg += '请输入市场价<br/>';
						mflg = 1;
					}
				}	
			})
			
			//规格信息(积分价)	
			$("input[name*=addPoints_]").each(function(){
				var a_price = $.trim($(this).val());	//积分价
				if(a_price != ''){
					//积分价
					if(!E.isInt(a_price) || a_price < 0){
						error_msg += '积分价必须为大于等于0的正整数<br>';
						return false;
					}
				}else{
					if(aflg == 0){
						error_msg += '请输入积分价<br/>';
						aflg = 1;
					}
				}	
			})
   
            if (error_msg != '')
                E.alert(error_msg);
            else
                E.confirm("您确认要添加商品信息吗？", "goods.add");
        },

        //保存
        add: function() {
        	editor.sync();
        	
        	//把需要保存的数据放到表单中(规格参数)
        	var colorData = [];
        	var sizeData = [];
        	for(var m = 0; m < COLORARRAY.length; m++){
        		if(COLORARRAY[m] == '' || COLORARRAY[m] == undefined)
        			continue;
        			
        		colorData.push(COLORARRAY[m]);	
        	}
        	
        	for(var n = 0; n < SIZEARRAY.length; n++){
        		if(SIZEARRAY[n] == '' || SIZEARRAY[n] == undefined)
        			continue;
        			
        		sizeData.push(SIZEARRAY[n]);		
        	}
        	
        	//图片和详情信息
        	var description = $('#description').val();
        	var hidImg_1    = $.trim($('#hidImg_1').val());
        	var hidImg_2    = $.trim($('#hidImg_2').val());
        	var hidImg_3    = $.trim($('#hidImg_3').val());
        	var hidImg_4    = $.trim($('#hidImg_4').val());
        	var hidImg_5    = $.trim($('#hidImg_5').val());
        	var hidImgData = {
        		'hidImg_1' 	  : hidImg_1, 
        		'hidImg_2' 	  : hidImg_2, 
        		'hidImg_3' 	  : hidImg_3, 
        		'hidImg_4' 	  : hidImg_4, 
        		'hidImg_5' 	  : hidImg_5,
        		'description' : description
        	};

        	//关键字信息
        	var keyData = new Array();
            $("input[name='addedKeywords']").each(function(k,v){
                var value = v.value;
                var t = v.checked;

                if( t == true ){
                    keyData.push(value);
                }

            })
			
        	var goodsData = {dt : this.dt, color : colorData, size : sizeData, img : hidImgData, key : keyData};

        	//ajax提交数据
            $.ajax({
                type: 'POST',
                url: "/invokingAjax-backend/goods/goodsAdd.ajax?operFlg=3",
                dataType: "JSON",
                data: goodsData,
                success: function( result_obj ) {
                    if(result_obj.code == 200){
                    	E.alert(result_obj.message, 2, 'E.refresh');

                    }else
                        E.alert(result_obj.message);
                }
            });
        },

        //添加外部编码输入框
        addOne:function( flg,addFlg ){
			var insertHtml = '<div id="externalNo_div_'+flg+'_'+tagAdd+'" style="height:30px;vertical-align:middle;">'+
							 '<input style="width:150px;font-weight:bold;font-size:15px;color:red;ime-mode:disabled;margin-right:10px;" type="text" name="externalNo_'+flg+'_'+tagAdd+'" id="externalNo_'+flg+'_'+tagAdd+'">' +
			       			 '<img id="img_removed_'+flg+'_'+tagAdd+'" src="/quanliadmin/docroot/images/bag_close.gif" onclick="goods.removed('+flg+','+tagAdd+')"></div>';
			
				//$("#img_add_" + flg).after(insertHtml);
				$('#externalNo_div_'+flg+'_'+addFlg).after(insertHtml);
				tagAdd ++ ;
        },

        //去除外部编码输入框
        removed:function( flg , tagAddFlg ){
            $("#externalNo_div_" + flg + '_' + tagAddFlg).remove();
            var html = $.trim( $("#td_" + flg).html() );
            if( html == '' )
                $("#add_" + flg).remove();

        }


	}
	
	//添加关键词
    function addKeyWords(){
        var keyWord = $.trim($("#keyWord").val());

        if( keyWord == '' ){
            E.alert('请输入关键字');
            return false;
        }

        //校验加入的关键字是否已经添加
        var exist = false;

        if( $("#keywordList").html() != '' ){

            $("input[name='addedKeywords']").each(function(){

                var objValue = $(this).val();

                if( objValue == keyWord ){
                    E.alert('关键字「' + objValue + '」已存在');
                    exist = true;
                }
            })

        }
        
        if( !exist ){
            document.getElementById('keywordList').innerHTML += '&nbsp;&nbsp;' +
            '<div style="width:450px;height:30px;background:#FFFFFF" class="list_nowrap">' +
            '<input type="checkbox" checked name="addedKeywords" value="' + keyWord + '"> ' + keyWord + "</div>";
            $("#keyWord").val("") ;
           
        }
		 $("#keyWord").select();
    }

</script>